/*!
 * 下拉日期控件.
 * ecp.qzz.ui.drop.popcalendar.js
 * 创建：QZZ
 * 日期：2014-03-01
 */
define(["qzz.pwindow","qzz.calendar"], function() {
	
	var qzz = window.qzz;
	qzz.space("ui.drop");
	/**
	 * 下拉日期控件.
	 */
	qzz.ui.drop.popcalendar = qzz.Class(qzz.ui.drop.popwindow, {
		/**
		 * 创建.
		 */
		_create:function() {			
		    this.base();
		    this.className = "PopCalendar";
		    this.logInfo("popCalendar.create");
		    //最大/小日期
		    this.maxDate = "9999-12-31";
		    this.minDate = "1000-01-01";
		    this.cyctype = "day";
		    this.showTime = false;
		    if(this.getOption().width == null || this.getOption().width == 10) {
		    	this.getOption().width = 192;
		    }
	    },
	    /**
	     * 渲染.
	     */
	    _render:function() {
	    	this.base();
	    	this.logInfo("popCalendar.render");
	    	//this.thisWindow.style.borderWidth = "0px";
	    	this.thisWindow.style.padding = "4px";
	    },
	    refreash:function() {
	    	this.refresh();
	    },
	    /**
	     * 刷新.
	     */
	    refresh:function() {
	    	if(this.isEmpty(this.calendar)) {
	    		//获取日期控件实例.
			    this.calendar = qzz.ui.calendar.getInstance(this._cssPrefix);
	    	}
	    	this.calendar.setParent(this.getDropWindow());
	    	//设置宽高
		    this.setWidth(this.calendar.getWidth() + 8);
		    this.setHeight(this.calendar.getHeight() + 8);
		    //设置最大最小值
		    this.calendar.setDate(this.date, false);
		    this.calendar.setMaxDate(this.maxDate,false);
	        this.calendar.setMinDate(this.minDate,false);	        
	        this.calendar.setShowTime(this.showTime);
	        this.calendar.setCycType(this.cyctype);
	        this.calendar._date = this;
		    this.calendar.onSelect = this.doSelect;
	    },
	    /**
	     * 执行选择.
	     * @param date 日期
	     */
	    doSelect:function(date) {
	    	var _this = this._date;
	    	_this.date = date;
	    	_this.hide();
	    	if(typeof _this.onSelect == "function") {
	    		_this.onSelect(date);
	    	}
	    },
	    /**
	     * 设置日期.
	     * @param date 日期
	     */
	    setDate:function(date){
	    	this.date = date;
	    },
	    /**
	     * 设置最大日期.
	     * @param date 日期
	     */
	    setMaxDate:function(date) {
	    	this.maxDate = date;
	    	
	    },
	    /**
	     * 设置最水日期.
	     * @param date 日期
	     */
	    setMinDate:function(date){
	    	this.minDate = date;	    	
	    },
	    /**
	     * 获取日期.
	     * @return 返回
	     */
	    getDate:function(){
	    	return this.date;
	    },
	    /**
	     * 检查日期格式.
	     * @param dateStr 日期
	     */
	    checkDate:function(dateStr) {
	    	if(this.isEmpty(this.calendar)) {
	    		//获取日期控件实例.
			    this.calendar = qzz.ui.calendar.getInstance(this._cssPrefix);
	    	}
		    return this.calendar.checkDate(dateStr);
	    },
	    /**
	     * 处理超出最大最小的情况.
	     */
	    checkRound:function(dateStr) {
	    	if(this.isEmpty(this.calendar)) {
	    		//获取日期控件实例.
			    this.calendar = qzz.ui.calendar.getInstance(this._cssPrefix);
	    	}
		    this.calendar.setMinDate(this.minDate, false);
		    this.calendar.setMaxDate(this.maxDate, false);
		    return this.calendar.checkRound(dateStr);
	    },
	    /**
	     * 失去焦点事件.
	     */
	    doBlur:function() {
	    	this.base();    	
	    	if(this.calendar != null) {
	    		this.calendar.setBlur();
	    	}
	    },
	    /**
	     * 设置显示时间标志.
	     * @param value 状态
	     */
	    setShowTime:function(value) {
	    	this.showTime = this.getBooleanValue(value, false);
	    	if(this.isEmpty(this.calendar)) {
	    		//获取日期控件实例.
			    this.calendar = qzz.ui.calendar.getInstance(this._cssPrefix);
	    	}
	    	this.calendar.setShowTime(this.showTime);
	    },
	    /**
	     * 日期周期.
	     */
	    setCycType:function(value) {
	    	this.cyctype = value;
	    	if(this.isEmpty(this.calendar)) {
	    		//获取日期控件实例.
			    this.calendar = qzz.ui.calendar.getInstance(this._cssPrefix);
	    	}
	    	this.calendar.setCycType(value);
	    },
	    /**
	     * 执行下拉展示.
	     */
	    execute:function(top, left, pHeight){
	    	this.refresh();
	    	this.base(top, left, pHeight);
	    }
	});
	_bindRenderFunc("qzzpopcalendar", qzz.ui.drop.popcalendar);
	return qzz.ui.drop.popcalendar;
});
	